package com.stdio.ui;

import java.util.HashMap;
import java.util.List;

import com.stdio.R;
import com.stdio.modle.PBInfor;
import com.stdio.modle.PeopleInfo;
import com.stdio.view.ContactDetailView;
import com.stdio.view.ContactEditTagView;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class ContactDetailActivity extends Activity {
	
	private String sContactId;
	private PBInfor mPbTool;
	private LayoutInflater mInflater;
	//private ContactEditTagView mEdittag;
	private List<HashMap<String,String>> contactInfo;
	private ContactDetailView mDetailview1;
	private ContactDetailView mDetailview2;
	private String mContactname;
	private TextView mContacttext;
	private ImageButton addcontact;
	private MyOnClickListener mylistener;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.layout_contact_details);
		mInflater = (LayoutInflater)this.getSystemService(LAYOUT_INFLATER_SERVICE);	
		
		mDetailview1 = (ContactDetailView)findViewById(R.id.list1);
		mDetailview2 = (ContactDetailView)findViewById(R.id.list2);
		mContacttext = (TextView)findViewById(R.id.TextView_Name);
		addcontact = (ImageButton)findViewById(R.id.edit_contact);
		
		mylistener = new MyOnClickListener();
		addcontact.setOnClickListener(mylistener);
		
		mContacttext = (TextView)findViewById(R.id.TextView_Name);
		addcontact = (ImageButton)findViewById(R.id.add_contact);
		
		mylistener = new MyOnClickListener();
		addcontact.setOnClickListener(mylistener);
		
		Intent intent = this.getIntent();
		Bundle bundle = intent.getExtras();
		sContactId = bundle.getString("contactId");
		initComponent(sContactId);
	}
	public void initComponent(String contactId)
	{
		mPbTool = new PBInfor(this);
		PeopleInfo mContactInfo = mPbTool.getContact(contactId);
		mContactname = mContactInfo.getDisplayName();
		
		if(mContactname!=null&&!"".equals(mContactname))
		{
			mContacttext.setText(mContactname);
		}
		String sContactphone = mContactInfo.getPhone();
		if(sContactphone!=null&&!"".equals(sContactphone))
		{
			mDetailview1.setDetailInfo(this.getResources().getString(R.string.contact_details_title_phone),sContactphone);
		}
		else
		{
			findViewById(R.id.phone_title).setVisibility(View.GONE);
			findViewById(R.id.phone_title_diviver_line).setVisibility(View.GONE);
			findViewById(R.id.list1).setVisibility(View.GONE);
		}
		String sEmail = mContactInfo.getEmail();
		if(sEmail!=null&&!"".equals(sEmail))
		{
			mDetailview2.setDetailInfo(this.getResources().getString(R.string.contact_details_title_email),sEmail);
		}
		else
		{
			findViewById(R.id.email_title).setVisibility(View.GONE);
			findViewById(R.id.email_title_diviver_line).setVisibility(View.GONE);
			findViewById(R.id.list2).setVisibility(View.GONE);
		}
		
	}
	private class MyOnClickListener implements View.OnClickListener
	{

		public void onClick(View v) {
			// TODO Auto-generated method stub
			Log.e("edit fasdf ", "vzxcvcvb");
			Intent intent;
			switch(v.getId())
			{
				case  R.id.edit_contact:
					
					intent = new Intent(ContactDetailActivity.this,ContactEditActivity.class);
					intent.setAction("android.intent.action.EDIT");
					Bundle extras = new Bundle();
					extras.putString("contactid", sContactId);
					intent.putExtras(extras);
					startActivity(intent);
					finish();
					break;
			}
		}
		
	}

		public void onClick(View v)
		{
			// TODO Auto-generated method stub
			Log.e("edit fasdf ", "vzxcvcvb");
			Intent intent;
			switch(v.getId())
			{
				case  R.id.add_contact:
					
					intent = new Intent(ContactDetailActivity.this,ContactEditActivity.class);
					intent.setAction("android.intent.action.EDIT");
					Bundle extras = new Bundle();
					extras.putString("contactid", sContactId);
					intent.putExtras(extras);
					startActivity(intent);
					finish();
					break;
			}
		}
		
	}


